/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package datos;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author monica
 */
@Entity
@Table(name = "programacion")
@NamedQueries({@NamedQuery(name = "Programacion.findAll", query = "SELECT p FROM Programacion p"),
@NamedQuery(name = "Programacion.findById", query = "SELECT p FROM Programacion p WHERE p.id = :id"),
@NamedQuery(name = "Programacion.findByFecha", query = "SELECT p FROM Programacion p WHERE p.fecha = :fecha"),
@NamedQuery(name = "Programacion.findByRetraso", query = "SELECT p FROM Programacion p WHERE p.retraso = :retraso"),
@NamedQuery(name = "Programacion.findByFechaModificacion", query = "SELECT p FROM Programacion p WHERE p.fechaModificacion = :fechaModificacion"),
@NamedQuery(name = "Programacion.findByTipo", query = "SELECT p FROM Programacion p WHERE p.tipo = :tipo"),
@NamedQuery(name = "Programacion.findByFechaFin", query = "SELECT p FROM Programacion p WHERE p.fechaFin = :fechaFin"),
@NamedQuery(name = "Programacion.existeFechaFin", query = "SELECT p.fechaFin FROM Programacion p WHERE p.idObra.id = :idObra AND p.idObra.eliminada = 0 AND p.fechaModificacion = (SELECT MAX(pp.fechaModificacion) FROM Programacion pp WHERE pp.idObra.id = :idObra AND pp.idObra.eliminada = 0)"),
@NamedQuery(name = "Programacion.encontrarPorObra", query = "SELECT p FROM Programacion p WHERE p.idObra.id = :idObra AND p.idObra.eliminada = 0 ORDER BY p.fechaModificacion ASC"),
@NamedQuery(name = "Programacion.ultimaFecha", query = "SELECT MAX (p.fechaModificacion) FROM Programacion p WHERE  p.idObra.id = :idObra AND p.idObra.eliminada = 0"),
@NamedQuery(name = "Programacion.ultimoMotivo2", query = "SELECT p.motivo FROM Programacion p WHERE  p.idObra.id = :idObra AND p.idObra.eliminada = 0 AND p.tipo = 'P'"),
@NamedQuery(name = "Programacion.ultimoMotivo", query = "SELECT p.motivo FROM Programacion p WHERE  p.idObra.id = :idObra AND p.idObra.eliminada = 0 AND p.fechaModificacion = (SELECT MAX(pp.fechaModificacion) FROM Programacion pp WHERE pp.idObra.id = :idObra AND pp.idObra.eliminada = 0)"),
@NamedQuery(name = "Programacion.motivosPorObra", query = "SELECT p FROM Programacion p WHERE  p.idObra.id = :idObra AND p.idObra.eliminada = 0  AND p.fechaModificacion IS NOT NULL"),
@NamedQuery(name = "Programacion.primeraProgramacion", query = "SELECT p FROM Programacion p WHERE p.tipo = 'P' AND p.idObra.id = :idObra AND p.idObra.eliminada = 0"),
@NamedQuery(name = "Programacion.ultimaProgramacion", query = "SELECT p FROM Programacion p WHERE p.idObra.id = :idObra AND p.idObra.eliminada = 0 AND p.fechaModificacion = (SELECT MAX(pp.fechaModificacion) FROM Programacion pp WHERE  pp.idObra.id = :idObra AND pp.idObra.eliminada = 0)"),
@NamedQuery(name = "Programacion.primerFecha", query = "SELECT MIN(p.fecha) FROM Programacion p WHERE p.idObra.id = :idObra AND p.idObra.eliminada = 0")})
public class Programacion implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "fecha")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecha;
    @Column(name = "retraso")
    private Float retraso;
    @Lob
    @Column(name = "alerta")
    private String alerta;
    @Lob
    @Column(name = "motivo")
    private String motivo;
    @Column(name = "fechaModificacion")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fechaModificacion;
    @Basic(optional = false)
    @Column(name = "tipo")
    private char tipo;
    @Column(name = "fechaFin")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fechaFin;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idProgramacion")
    private Collection<DetalleProgramacion> detalleProgramacionCollection;
    @JoinColumn(name = "idObra", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Obra idObra;

    public Programacion() {
    }

    public Programacion(Integer id) {
        this.id = id;
    }

    public Programacion(Integer id, Date fecha, char tipo) {
        this.id = id;
        this.fecha = fecha;
        this.tipo = tipo;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getFecha() {
        return fecha;
    }

    public void setFecha(Date fecha) {
        this.fecha = fecha;
    }

    public Float getRetraso() {
        return retraso;
    }

    public void setRetraso(Float retraso) {
        this.retraso = retraso;
    }

    public String getAlerta() {
        return alerta;
    }

    public void setAlerta(String alerta) {
        this.alerta = alerta;
    }

    public String getMotivo() {
        return motivo;
    }

    public void setMotivo(String motivo) {
        this.motivo = motivo;
    }

    public Date getFechaModificacion() {
        return fechaModificacion;
    }

    public void setFechaModificacion(Date fechaModificacion) {
        this.fechaModificacion = fechaModificacion;
    }

    public char getTipo() {
        return tipo;
    }

    public void setTipo(char tipo) {
        this.tipo = tipo;
    }

    public Date getFechaFin() {
        return fechaFin;
    }

    public void setFechaFin(Date fechaFin) {
        this.fechaFin = fechaFin;
    }

    public Collection<DetalleProgramacion> getDetalleProgramacionCollection() {
        return detalleProgramacionCollection;
    }

    public void setDetalleProgramacionCollection(Collection<DetalleProgramacion> detalleProgramacionCollection) {
        this.detalleProgramacionCollection = detalleProgramacionCollection;
    }

    public Obra getIdObra() {
        return idObra;
    }

    public void setIdObra(Obra idObra) {
        this.idObra = idObra;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Programacion)) {
            return false;
        }
        Programacion other = (Programacion) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "datos.Programacion[id=" + id + "]";
    }

}
